草庐IT

Java `final` 类和模拟

全部标签

unit-testing - 如何为单元测试模拟标准包函数

我有三个功能:funcIsSymlinks(pathstring){......}func(c*MyClass)myFunc1(pathstring){...morecode...morecodeifIsSymlinks(path){realPath:=filepath.EvalSymlinks(path)}...morecode...morecode}funcmyFunc2(pathstring){...morecode...morecodeifIsSymlinks(path){realPath:=filepath.EvalSymlinks(path)}...morecode...m

go - 如何从 Visual Studio Code 中的包覆盖范围中排除生成的模拟

我正在通过VisualStudioCode对Golang项目进行单元测试,我使用的依赖项之一称为mockery.它通过在找到的包中创建目标Golang接口(interface)的模拟来工作。因此,即使我发誓要测试所述包中的所有内容,我的测试覆盖率也只有58%。然而,当我从包中取出模拟(事实证明我不需要它)时,我的测试覆盖率肯定像雨一样猛增到我预期的97.9%。有什么方法可以告诉VisualStudioCode“嘿,不要在包覆盖率计算中包含模拟模拟(以mock_开头)”? 最佳答案 解决方案是使用mockery-inpkg和-test

go - 测试中的模拟方法

我有一个要测试的类:typeApiGatewaystruct{usernamestringpasswordstringscsClient*scsClient.APIDocumentationauthAuth}typeAuthstruct{tokenstringvalidToint32}funcNew(hoststring,schemestring,usernamestring,passwordstring)*ApiGateway{varconfig=scsClient.TransportConfig{host,"/",[]string{scheme}}varclient=scsClie

go - 在 golang 中模拟内部函数

我想使用接口(interface)模拟函数,我能够模拟第一个函数callsomething在icza的大力帮助下,现在有点棘手了。我想测试函数vl1使用mockforfunctionfunction1,它是如何完成的。https://play.golang.org/p/w367IOjADFV主要包import("fmt""time""testing")typevInterfaceinterface{function1()bool}typemStructstruct{infostringtimetime.Time}func(s*mStruct)function1()bool{return

unit-testing - 如何在 Golang 中实现 stub ? stub 和模拟之间有什么区别?

关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭4年前。Improvethisquestion我在Golang的单元测试中使用模拟。但是在Golang的实现代码中如何区分stub和mock呢?

go - 如何在 golang 中模拟 GCP 的存储?

我真的不熟悉在go中模拟第三方库,我现在正在模拟cloud.google.com/go/storage我正在使用mockery.这是我当前的界面://ClientstorageclienttypeClientinterface{Bucket(namestring)BucketHandleBuckets(ctxcontext.Context,projectIDstring)BucketIterator}//BucketHandlestorage'sBucketHandletypeBucketHandleinterface{Attrs(context.Context)(*storage.B

go - 我如何模拟接口(interface)内的特定嵌入式方法

我有这段代码,我想为更新功能编写一个单元测试。我如何模拟FindByUsername函数?我尝试覆盖u.FindByUsername但它不起作用。另外,我可以编写一些函数来将u*UserLogic和userNamestring作为输入参数并执行u.FindByUsername()和模拟这个函数,但这不是一个干净的解决方案我需要一个更好的解决方案来模拟UserOperation接口(interface)中的方法。packagelogicimport("errors""fmt")var(dataStore=map[string]*User{"optic":&User{Username:"b

java - 向 TCP 服务器指示 Java TCP 客户端已完成写入流

我正在编写一个连接到GolangTCP服务器的JavaTCP客户端。服务器使用以下代码从客户端读取消息:func(tcpHandlerTCPHandler)getClientMsgBytes(connection*net.TCPConn)([]byte,error){clientMsgBytes,err:=ioutil.ReadAll(connection)iferr!=nil{returnnil,err}returnclientMsgBytes,nil}我的客户端使用以下代码向服务器发送消息:try(Socketsocket=newSocket("localhost",9000)){

go - 如何检查 Cloud Pub/Sub 模拟器是否已启动并正在运行?

我有GC功能,我使用CloudPub/Sub模拟器在本地开发和测试这些功能。我希望能够从Go代码中检查CloudPub/Sub模拟器是否已启动并正在运行。如果没有,我想通知开发人员他/她应该在他/她在本地执行代码之前启动模拟器。当模拟器启动时我注意到一条线INFO:Serverstarted,listeningon8085也许我可以检查端口是否可用或类似。 最佳答案 我猜你用过这个命令:gcloudbetaemulatorspubsubstart你得到了以下输出:[pubsub]ThisistheGooglePub/Subfake.

java - 与Levenshtein的快速比较

Closed.Thisquestionneedstobemorefocused。它当前不接受答案。想改善这个问题吗?更新问题,使其仅关注editingthispost一个问题。去年关闭。Improvethisquestion我正在尝试寻找一种最佳方法,将一个文本(最大长度:300)与Levenshtein的300.000进行比较。最后,我需要一个带有简单RESTAPI的Web服务。将来,条目数将超过300.000。在后台,我正在使用一个简单的MySQL数据库。我的第一个想法是使用MySQL来完成这项工作。为此,我找到了这个:https://github.com/juanmirocks/